﻿using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;

namespace ERP.Abp.AntDesignUI
{
    public partial class ReuseTabs : AntDesign.AntDomComponentBase
    {
        [Parameter]
        public string TabPaneClass { get; set; }

        [Parameter]
        public bool Draggable { get; set; }

        [Parameter]
        public AntDesign.TabSize Size { get; set; }

        [Parameter]
        public RenderFragment<ReuseTabsPageItem> Body { get; set; }= context => context.Body;

        [Parameter]
        public AntDesign.ReuseTabsLocale Locale { get; set; }// AntDesign.LocaleProvider.CurrentLocale.ReuseTabs;

        [Inject]
        public NavigationManager Navmgr { get; set; }

        [CascadingParameter(Name = "RouteView")]
        public ReuseTabsRouteView RouteView { get; set; }

        private ReuseTabsPageItem[]? Pages => RouteView?.Pages;

        private string CurrentUrl
        {
            get => Navmgr?.Uri;
            set => Navmgr?.NavigateTo(value);
        }

        private void RemovePage(string key)
        {
            this.RouteView?.RemovePage(key);
            StateHasChanged();
        }

        private void RemoveOther(string key)
        {
            foreach (var item in Pages.Where(x => x.Closable && x.Url != key))
            {
                this.RouteView?.RemovePage(item.Url);
            }
            StateHasChanged();
        }

        private void RemoveAll()
        {
            foreach (var item in Pages.Where(x => x.Closable))
            {
                this.RouteView?.RemovePage(item.Url);
            }
            StateHasChanged();
        }
        Task<bool> OnEdit(string key, string action)
        {
          
         
            return Task.FromResult(true);
        }
        void OnChange(string key)
        {
         
        }
        void OnTabClick(string key)
        {
          
          
        }
    }
}
